package chapter3.lc125;

//LC 125 验证回文串 忽略大小写

/**
 * 双指针往中间夹
 * 用!Character.isLetterOrDigit跳过分隔符
 * 一开始真个string转小写会更好
 */
public class ValidPalindrome {
    public boolean isPalindrome(String s) {
        for (int i = 0, j = s.length() - 1; i < j;) {
            if (!Character.isLetterOrDigit(s.charAt(i))) {
                i++;
                continue;
            }
            if (!Character.isLetterOrDigit(s.charAt(j))) {
                j--;
                continue;
            }
            if (Character.toLowerCase(s.charAt(i)) != Character.toLowerCase(s.charAt(j))){
                return false;
            }
            i++;
            j--;
        }
        return true;
    }
}
